package com.singzi.leetcode.N400;

public class T0372 {
    public static void main(String[] args) {
        Solution0372 solution0372 = new Solution0372();
        int [] nums = {2,0,0};
        System.out.println(solution0372.superPow(2147483647, nums));

    }
}

class Solution0372 {
    public int superPow(int a, int[] b) {

        int obj = 1337;
        int remain = a%obj;
        int []remain0 = new int[b.length];
        remain0[0] = remain;
        for (int i = 1; i < b.length; i++) {
            remain0[i] = 1;
            for (int i1 = 0; i1 < 10; i1++) {
                remain0[i] = remain0[i] * remain0[i-1] % obj;
            }
        }
        int result = 1;
        int j;
        for (int i = b.length-1; i >= 0; i--) {
            if(b[i]==0) continue;
            j = b.length - 1- i;
            for (int k = 0; k < b[i]; k++) {
                result =  result * remain0[j]%obj;
            }
        }

        return result;

    }

}